<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        :showHeaderOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config='tableToolbar'
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button v-has="'product-center:add'" @click='handleAdd'>新增</a-button>
            <a-button v-has="'product-center:delete'" @click='batchDel'>删除</a-button>
            <a-button v-has="'product-center:export'"  @click=''>导出</a-button>
          </div>
        </template>

        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.productCode }}</a>
        </template>
        <template #materialType='{ row }'>
          {{ row.materialType == 1 ? '产自品' : '促销物料' }}
        </template>
        <template #transportationType='{ row }'>
          {{ row.transportationType == 1 ? '速冻' : '常温' }}
        </template>
        <template #action='{ row }'>
          <a  v-has="'product-center:update'"  @click='handleEdit(row)'>编辑</a>
          <a-divider type='vertical' />
          <a v-has="'business:log'" href='javascript:;' @click='handleBusiness("产品管理",row)'>日志</a>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- 表单区域 -->
    <business-log ref='businessLog'></business-log>
    <product-modal ref='modalForm' @ok='modalFormOk'></product-modal>
  </a-card>
</template>

<script>
import { getProductCategory } from '@/api/api'
import productModal from './modules/ProductModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import Vue from 'vue'
import { filterObj } from '@/utils/util'
import { getAction } from '@/api/manage'

export default {
  name: 'product-list',
  mixins: [PageListMixin],
  components: {
    productModal,
  },
  data() {
    return {
      description: '产品管理',
      searchConfig: [
        {
          // label:'订单编号',
          type: 'input',
          name: 'productCode',
          placeholder: '产品编号'
        },
        {
          type: 'input',
          name: 'productName',
          placeholder: '产品名称'
        },
        {
          type: 'input',
          name: 'productClassificationName',
          placeholder: '产品分类'
        },
        {
          type: 'input',
          name: 'barCode',
          placeholder: '条码'
        },
        {
          type: 'input',
          name: 'materialGroupName',
          placeholder: '物料组名称'
        },
        {
          type: 'input',
          name: 'materialGroupCode',
          placeholder: '物料组编号'
        }
        ],
      //表头
      columns: [
        { type: 'checkbox', width: 60, fixed: 'left' },
        {
          title: '产品编号',
          minWidth: 100,
          fixed: 'left',
          field: 'productCode',
          slots: {
            default: 'detail'
          }
        },
        {
          title: '产品名称',
          minWidth: 100,
          field: 'productName'
        },
        {
          title: '条码',
          minWidth: 100,
          field: 'barCode'
        },
        {
          title: '规格',
          minWidth: 100,
          field: 'specifications'
        },
        {
          title: '产品分类',
          minWidth: 100,
          field: 'productClassificationName'
        },
        {
          title: '助记码',
          minWidth: 100,
          field: 'mnemonicCode'
        },
        {
          title: '有效期',
          minWidth: 100,
          field: 'termOfValidity'
        },
        {
          title: '品牌',
          minWidth: 100,
          field: 'brand'
        },
        {
          title: 'adc分类',
          minWidth: 100,
          field: 'abcClassify'
        },
        {
          title: '主单位名称',
          minWidth: 100,
          field: 'mainUnitName'
        },
        {
          title: '辅单位名称',
          minWidth: 100,
          field: 'auxiliaryUnitName'
        },
        {
          title: '单件毛重',
          minWidth: 100,
          field: 'grossWeight'
        },
        {
          title: '单件最小毛重',
          minWidth: 100,
          field: 'minGrossWeight'
        },
        {
          title: '批次',
          minWidth: 100,
          field: 'batch'
        },
        {
          title: '删除标志',
          minWidth: 100,
          field: 'status'
        },
        {
          title: '单件体积',
          minWidth: 100,
          field: 'unitVolume'
        },
        {
          title: '单件净重',
          minWidth: 100,
          field: 'unitNetWeight'
        },
        {
          title: '折合系数',
          minWidth: 100,
          field: 'coefficient'
        },
        {
          title: '物料类型',
          minWidth: 100,
          field: 'materialType',
          slots: { default: 'materialType' }
        },
        {
          title: '单托件',
          minWidth: 100,
          field: 'consignmentQuantity'
        },
        {
          title: '运输类型',
          minWidth: 100,
          field: 'transportationType',
          slots: { default: 'transportationType' }
        },
        {
          title: '计算运费特殊产品',
          minWidth: 100,
          field: 'calculateFreight'
        },
        {
          title: '详细描述',
          minWidth: 100,
          field: 'remarks'
        },
        {
          title: '主辅单位换算率',
          minWidth: 100,
          field: 'unitConversionRate'
        },
        {
          title: '比例',
          minWidth: 100,
          field: 'proportion'
        },
        {
          title: '产品档次编号',
          minWidth: 100,
          field: 'productGradeCode'
        },
        {
          title: '产品档次描述',
          minWidth: 100,
          field: 'productGradeDescribe'
        },
        {
          title: '产品分类(系列)编号',
          minWidth: 100,
          field: 'productClassifyCode'
        },
        {
          title: '产品分类(系列)描述',
          minWidth: 100,
          field: 'productClassifyDescribe'
        },
        {
          title: '预算产品规格分类',
          minWidth: 100,
          field: 'normsClassify'
        },
        {
          title: '预算产品规格分类描述',
          minWidth: 100,
          field: 'normsClassifyDescribe'
        },
        {
          title: '物料组名称',
          minWidth: 100,
          field: 'materialGroupName'
        },
        {
          title: '物料组编号',
          minWidth: 100,
          field: 'materialGroupCode'
        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 80,
          field: 'updateTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          width: 120,
          slots: {
            default: 'action'
          }
        }
      ],
      url: {
        list: window._CONFIG['domianURL'] + '/products/cnProduct/findPageList',
        delete: window._CONFIG['domianURL'] + '/products/cnProduct/delete',
        detail: window._CONFIG['domianURL'] + '/products/cnProduct/getInfo',
        deleteBatch: window._CONFIG['domianURL'] + '/products/cnProduct/deleteBatch'
        // startOrStopUrl: window._CONFIG['domianURL'] + '/liftingcapacityconfig/cnLiftingCapacityConfig/startOrStop'
      }
    }
  },
  created() {

  },
  methods: {

    handleEdit: function(record) {
      getAction(this.url.detail, { id: record.id }).then(res => {
        if (res.success) {
          this.$refs.modalForm.edit(res.result)
          this.$refs.modalForm.title = '编辑'
          this.$refs.modalForm.disableSubmit = false
        } else {
          this.$message.error(res.message)
        }
      })

    },
    getQueryParams() {
      //高级查询器
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

      param.field = this.getQueryField()
      param.current = this.ipagination.current
      param.size = this.ipagination.pageSize
      delete param.birthdayRange //范围参数不传递后台
      return filterObj(param)
    }

  }

}
</script>
<style scoped>

</style>